package com.czk.util;

import com.czk.domain.ServerMsgProtocol;
import com.alibaba.fastjson.JSON;
import io.netty.handler.codec.http.websocketx.TextWebSocketFrame;

/**
 * 消息工具类
 *
 * @Author:ChenZhangKun
 * @Date: 2021/4/25 11:14
 */
public class MsgUtil {
    public static TextWebSocketFrame buildMsgAll(String channelId, String message) {
        // 模拟头像
        int i = Math.abs(channelId.hashCode()) % 10;
        ServerMsgProtocol serverMsgProtocol = new ServerMsgProtocol();
        serverMsgProtocol.setType(2);
        serverMsgProtocol.setChannelId(channelId);
        serverMsgProtocol.setUserHeadMsg("head" + i + ".msg");
        serverMsgProtocol.setMsgInfo(message);
        return new TextWebSocketFrame(JSON.toJSONString(message));
    }

    public static TextWebSocketFrame buildMsgOwner(String channelId) {
        ServerMsgProtocol msg = new ServerMsgProtocol();
        // 链接信息;1链接信息、2消息信息
        msg.setType(1);
        msg.setChannelId(channelId);
        return new TextWebSocketFrame(JSON.toJSONString(msg));
    }
}
